<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Login</title>
        
        <link href="Style.css" rel="stylesheet" type="text/css" />
        <script src="jquery-1.7.2.min.js" type="text/javascript"></script>
        <script src="Ponto.js" type="text/javascript"></script>
        <script src="Common.js" type="text/javascript"></script>
        <script type="text/javascript">

        function Alert() {
            this.show = function(params) {
                  alert("result ==== "+params.result);
            };
        }

        Ponto.PontoBaseHandler.derive(Alert);




            $(document).ready(function(){
                              $("#sendCaptureButton").bind("click", function(){
                                                           if (!checkPhone()){
                                                           return;
                                                           }
                                                           $("#errorDiv").html("发送中...");
                                                           $.ajax({
                                                                  url: "http://testvms.yqphh.com/purchase/driver/recoveryAccessCode",
                                                                  data: {
                                                                  phone_number: $("#phoneInput").val()
                                                                  },
                                                                  type: "post",
                                                                  dataType: "json",
                                                                  
                                                                  error: function() {
                                                                  $("#errorDiv").html("获取验证码错误");
                                                                  },
                                                                  
                                                                  success: function(data) {
                                                                  if (data.result == "ok"){
                                                                  $("#errorDiv").html("验证码已发送：" + data.access_code);
                                                                  }
                                                                  else{
                                                                  $("#errorDiv").html("error_code: " + data.error_code + "<br/>error_info: " + data.error_info);
                                                                  }
                                                                  }
                                                                  });
                                                           });
                              $("#loginButton").bind("click", function(){
                                                     if (!checkPhone() || !checkCapture()){
                                                     return;
                                                     }
                                                     $("#errorDiv").html("登录中...");
                                                     $.ajax({
                                                            url: "http://testvms.yqphh.com/purchase/driver/login",
                                                            data: {
                                                            phone_number: $("#phoneInput").val(),
                                                            access_code: $("#captureInput").val()
                                                            },
                                                            type: "post",
                                                            dataType: "json",
                                                            
                                                            error: function() {
                                                            $("#errorDiv").html("登录错误");
                                                            window.location.href = "Task.html";
                                                            },
                                                            
                                                            success: function(data) {
                                                            if (data.result == "ok"){
                                                            $("#errorDiv").html("");
                                                            setCookie("phone", $("#phoneInput").val(), 10);
                                                            window.location.href = "Task.html";

                                                            }
                                                            else{
                                                            $("#errorDiv").html("error_code: " + data.error_code + "<br/>error_info: " + data.error_info);
                                                            }
                                                            }
                                                            });
                                                     });
                              });
                              
                              $(window).load(function(){
                                             //$("#phoneInput").val(getCookie("phone"));
                                             });
                              
                              function checkPhone(){
                                  
                                  if ($("#phoneInput").val() == "") {
                                      $("#errorDiv").html("请输入手机号码！");
                                      return false;
                                  }
                                  if (!$("#phoneInput").val().match(/^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1})|(14[0-9]{1}))+\d{8})$/)) {
                                      $("#errorDiv").html("手机号码格式不正确！");
                                      return false;
                                  }
                                  return true;
                              }
        
        function checkCapture(){
            
            if ($("#captureInput").val() == "") {
                $("#errorDiv").html("请输入验证码！");
                return false;
            }
            return true;
        }

        </script>
        
        <style type="text/css">
            table{
                height: 150px;
            }
        #captureInput{
            float: left;
            width:50%;
        }
        #sendCaptureButton{
            background: #3498DB;
            float: right;
            margin-top: 5px;
            width:45%;
        }
        #loginButton{
            background: #2ECC71;
        }
        
        </style>
    </head>
    <body>
        <table cellpadding="0" cellspacing="0">
            <tr>
                <td>
                    <input id="phoneInput" placeholder="手机号" type="number"/>
                </td>
            </tr>
            <tr>
                <td>
<!--                    437006-->
                    <input id="captureInput" placeholder="验证码" type="number"/>
                    <button id="sendCaptureButton">发送验证码</button>
                </td>
            </tr>
            <tr>
                <td>
                    <button id="loginButton">登录</button>
                </td>
            </tr>
            <tr>
                <td>
                    <div id="errorDiv"></div>
                </td>
            </tr>
            <tr>
                <td>
                    <button onclick="setStatus(123,0)">定位测试</button>
                </td>
            </tr>
            <tr>
                <td>
                    <button onclick="setStatus(123,1)">卸货完成测试</button>
                </td>
            </tr>
            <tr>
                <td>
                    <button onclick="toCall(13097339358)">电话测试</button>
                </td>
            </tr>
            <tr>
                <td>
                    <button onclick="login(13097339358,891813)">登录测试</button>
                </td>
            </tr>
        </table>
    </body>
</html>